package app.widget;

import android.text.Html.TagHandler;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

/**
 * @author EX-YUWEI001
 * @date 2011-12-14
 * @description TODO 公共类：tab滑动动画监听器，所有tab滑动动画都必须设置该类实例的的监听器
 */
public class MoveAnimationListener implements
		android.view.animation.Animation.AnimationListener {
	RadioGroup radio;
	RadioButton radioBtn;
	int movetoX;
	ImageView bgView;
	float width;
	float imageWidth;

	/**
	 * @param group
	 * @param targetBtn
	 *            目标radioButton
	 * @param value
	 *            移动到坐标
	 * @param image
	 */
	public MoveAnimationListener(RadioGroup group, RadioButton targetBtn,
			int value, ImageView image) {
		// TODO Auto-generated constructor stub
		this.radio = group;
		this.radioBtn = targetBtn;
		this.movetoX = value;
		this.bgView = image;
		imageWidth = image.getWidth();
		width = targetBtn.getWidth();
	}

	public void onAnimationEnd(Animation animation) {
		// TODO Auto-generated method stub
		bgView.clearAnimation();
		// radioBtn.measure(0, 0);
		// width=radioBtn.getMeasuredWidth();
		RelativeLayout.LayoutParams params = (LayoutParams) bgView
				.getLayoutParams();
		params.leftMargin = movetoX;
		params.width = radioBtn.getWidth();
		bgView.setLayoutParams(params);
		for (int i = 0; i < radio.getChildCount(); i++) {
			RadioButton button = (RadioButton) radio.getChildAt(i);
			button.setEnabled(true);
		}

	}

	public void onAnimationRepeat(Animation animation) {
		// TODO Auto-generated method stub

	}

	public void onAnimationStart(Animation animation) {
		// TODO Auto-generated method stub

		// ScaleAnimation animate = new ScaleAnimation(1.0f, width / imageWidth,
		// 1.0f, 1.0f);
		// animate.setDuration(500);
		//
		// bgView.startAnimation(animate);
	}
}
